/*
 * @Author: youngqj youngqj@126.com
 * @Date: 2024-10-21 20:05:35
 * @LastEditors: youngqj youngqj@126.com
 * @LastEditTime: 2024-12-04 17:10:09
 * @FilePath: /mallSystem/routes/auth.go
 * @Description:
 *
 * Copyright © Zhejiang Xiaoqu Information Technology Co., Ltd, All Rights Reserved.
 */
package routes

import (
	"xiaoquio/web/app/handler"
	"xiaoquio/web/app/service"
	"xiaoquio/web/middleware"

	"github.com/gin-gonic/gin"
)

func SetupAuthRoutes(r *gin.Engine) {
	// 不需要鉴权的路由组
	public := r.Group("/auth")
	public.Use(middleware.DBMiddleware("default"))
	{
		public.POST("/reg", handler.Register)                                       // 注册
		public.POST("/login", middleware.RedisMiddleware("default"), handler.Login) // 登录
	}

}

func SetupMemberRoutes(r *gin.Engine) {

	memberService := service.NewMemberService()
	memberHandler := handler.NewMemberHandler(memberService)

	// 需要鉴权的路由组
	memberGroup := r.Group("/member")
	memberGroup.Use(middleware.RedisMiddleware("default"), middleware.AuthMiddleware(), middleware.DBMiddleware("default")) // 使用鉴权中间件
	{
		memberGroup.GET("/info/:id", memberHandler.GetUserInfo) // 获取用户信息
		memberGroup.GET("/list", memberHandler.FindAllMembers)  // 获取用户列表
	}

	merchantService := service.NewMerchantService()
	merchantHandler := handler.NewMerchantHandler(merchantService)
	// 需要鉴权的路由组
	merchantGroup := r.Group("/merchant")
	merchantGroup.Use(middleware.RedisMiddleware("default"), middleware.AuthMiddleware(), middleware.DBMiddleware("datas")) // 使用鉴权中间件
	{
		merchantGroup.GET("/info/:id", merchantHandler.GetUserInfo) // 获取用户信息
		merchantGroup.GET("/list", merchantHandler.FindAllMembers)  // 获取用户列表
	}
}
